<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>第一节课</title>
		<style type="text/css">
			/*去除原来样式*/
			
			* {
				padding: 0;
				margin: 0;
			}
			
			.container {
				width: 100vw;
				height: 100vh;
				display: flex;
				/*
				 * 将边框设置在中间
				 */
				align-items: center;
				justify-content: center;
			}
			
			canvas {
				width: 1100px;
				height: 500px;
				border: 1px solid #333333;
			}
		</style>
	</head>

	<body>
		<div class="container">
			<canvas id="canvas" width="1100" height="500"></canvas>
			
		</div>
	</body>

	<script>
		
		window.onload = function() {
			//let oCanvas = document.getElementById('canvas');
			let oCanvas = document.getElementById("canvas");
			let pen = oCanvas.getContext("2d");

			var image = new Image();
			image.src = '../course06/img.png';
			
			image.onload = function(){
				pen.drawImage(image,0,0,500,500);
				var imageData = pen.getImageData(0,0,500,500)
				var data = imageData.data;
				console.log(data);
				
					/*for(var i=0;i<data.length;i+=4){
						var average=(data[i+0]+data[i+1]+data[i+2]+data[i+3])/3;
						data[i+0] += average;
						data[i+1] += average;
						data[i+2] += average;
					}*/
					
					for(var i=0;i<data.length;i+=4){
						var grayscale=data[i+0]*0.3+data[i+1]*0.6+data[i+2]*0.1;
						data[i+0] += grayscale;
						data[i+1] += grayscale;
						data[i+2] += grayscale;
					}
					
					
				pen.putImageData(imageData,600,0);
				
			
				
			}
			
			
		}
	</script>

</html>